Completed
Push — master ( 02f1f2...7972c9 )
by Yannick
33:11
created

map.common.js ➔ noarchive   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
cc 1
c 3
b 1
f 0
nc 1
dl 0
loc 8
rs 9.4285
nop 0
1
function getCookie(cname) {
2
    var name = cname + "=";
3
    var ca = document.cookie.split(';');
4
    for(var i=0; i<ca.length; i++) {
5
	var c = ca[i];
6
	while (c.charAt(0)==' ') c = c.substring(1);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
7
	if (c.indexOf(name) == 0) return c.substring(name.length,c.length);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
8
    }
9
    return "";
10
}
11
12
function delCookie(cname) {
13
    document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';
14
}
15
16
function createCookie(name, value, days) {
17
    var date, expires;
18
    if (days) {
19
	date = new Date();
20
	date.setTime(date.getTime()+(days*24*60*60*1000));
21
	expires = "; expires="+date.toGMTString();
22
    } else {
23
	expires = "";
24
    }
25
    document.cookie = name+"="+value+expires+"; path=/";
26
}
27
28
function dynamicSort(property) {
29
    var sortOrder = 1;
30
    if(property[0] === "-") {
31
        sortOrder = -1;
32
        property = property.substr(1);
33
    }
34
    return function (a,b) {
35
        var result = (a[property] < b[property]) ? -1 : (a[property] > b[property]) ? 1 : 0;
36
        return result * sortOrder;
37
    }
38
}
39
40
function dynamicSortMultiple() {
41
    var props = arguments;
42
    return function (obj1, obj2) {
43
	var i = 0, result = 0, numberOfProperties = props.length;
44
	while(result === 0 && i < numberOfProperties) {
45
	    result = dynamicSort(props[i])(obj1, obj2);
46
	    i++;
47
	}
48
	return result;
49
    }
50
}
51
52
function mapType(selectObj) {
53
    var idx = selectObj.selectedIndex;
54
    var atype = selectObj.options[idx].value;
55
    var type = atype.split('-');
56
    if (type[0] == 'Mapbox') {
57
	createCookie('MapType',type[0],9999);
58
	createCookie('MapTypeId',type[1],9999);
59
	if (getCookie('Map2D3DSync')) {
60
	    createCookie('MapType3D',type[0],9999);
61
	    createCookie('MapType3DId',type[1],9999);
62
	}
63
    } else {
64
	createCookie('MapType',atype,9999);
65
	if (getCookie('Map2D3DSync')) {
66
	    createCookie('MapType3D',atype,9999);
67
	}
68
    }
69
    window.location.reload();
70
}
71
function mapType3D(selectObj) {
72
    var idx = selectObj.selectedIndex;
73
    var atype = selectObj.options[idx].value;
74
    var type = atype.split('-');
75
    if (type[0] == 'Mapbox') {
76
	createCookie('MapType3D',type[0],9999);
77
	createCookie('MapType3DId',type[1],9999);
78
	if (getCookie('Map2D3DSync')) {
79
	    createCookie('MapType',type[0],9999);
80
	    createCookie('MapTypeId',type[1],9999);
81
	}
82
    } else {
83
	createCookie('MapType3D',atype,9999);
84
	if (getCookie('Map2D3DSync')) {
85
	    createCookie('MapType',atype,9999);
86
	}
87
    }
88
    window.location.reload();
89
}
90
function clickSyncMap2D3D(cb) {
91
    createCookie('Map2D3DSync',cb.checked,9999);
92
    if (cb.checked) {
93
	createCookie('MapType3D',getCookie('MapType'),9999);
94
	createCookie('MapType3DId',getCookie('MapTypeId'),9999);
95
    }
96
}
97
98
function terrainType(selectObj) {
99
    var idx = selectObj.selectedIndex;
100
    var atype = selectObj.options[idx].value;
101
    var type = atype.split('-');
102
    document.cookie =  'MapTerrain='+type+'; expires=Thu, 2 Aug 2100 20:47:11 UTC; path=/'
103
    createCookie('MapTerrain',type,9999);
104
    if (type == 'stk') {
105
	stkterrain();
106
    } else if (type == 'articdem') {
107
	articterrain();
108
    } else if (type == 'ellipsoid') {
109
	ellipsoidterrain();
110
    } else if (type == 'vrterrain') {
111
	vrtheworldterrain();
112
    }
113
    //window.location.reload();
114
}
115
116
function sattypes(selectObj) {
117
    var sattypes = [], sattype;
118
    for (var i=0, len=selectObj.options.length; i< len;i++) {
119
	sattype = selectObj.options[i];
120
	if (sattype.selected) {
121
	    sattypes.push(sattype.value);
122
	}
123
    }
124
    createCookie('sattypes',sattypes.join(),2);
125
    updateSat();
126
}
127
function airlines(selectObj) {
128
    var airs = [], air;
129
    for (var i=0, len=selectObj.options.length; i< len;i++) {
130
	air = selectObj.options[i];
131
	if (air.selected) {
132
	    airs.push(air.value);
133
	}
134
    }
135
    createCookie('filter_Airlines',airs.join(),2);
136
}
137
function airlinestype(selectObj) {
138
    var idx = selectObj.selectedIndex;
139
    var airtype = selectObj.options[idx].value;
140
    createCookie('filter_airlinestype',airtype,2);
141
}
142
function racefilter(selectObj) {
143
    var idx = selectObj.selectedIndex;
144
    var race = selectObj.options[idx].value;
145
    if (race == 'all') {
146
	delCookie('filter_race');
147
    } else {
148
	createCookie('filter_race',race,2);
149
    }
150
    if (getCookie['MapFormat'] == '3d') {
151
	updateMarineData();
152
    } else {
153
	getLiveMarineData(0);
154
    }
155
}
156
function alliance(selectObj) {
157
    var idx = selectObj.selectedIndex;
158
    var alliance = selectObj.options[idx].value;
159
    createCookie('filter_alliance',alliance,2);
160
}
161
function identfilter() {
162
    var ident = $("#identfilter").value;
163
    createCookie('filter_ident',ident,2);
164
}
165
function mmsifilter() {
166
    var ident = $("#mmsifilter").value;
167
    createCookie('filter_mmsi',ident,2);
168
}
169
function removefilters() {
170
    // Get an array of all cookie names (the regex matches what we don't want)
171
    var cookieNames = document.cookie.split(/=[^;]*(?:;\s*|$)/);
172
    // Remove any that match the pattern
173
    for (var i = 0; i < cookieNames.length; i++) {
174
	if (/^filter_/.test(cookieNames[i])) {
175
	    delCookie(cookieNames[i]);
176
	}
177
    }
178
    window.location.reload();
179
}
180
function sources(selectObj) {
181
    var sources = [], source;
182
    for (var i=0, len=selectObj.options.length; i< len;i++) {
183
	source = selectObj.options[i];
184
	if (source.selected) {
185
	    sources.push(source.value);
186
	}
187
    }
188
    createCookie('filter_Sources',sources.join(),2);
189
}
190
191
192
function show2D() {
193
    createCookie('MapFormat','2d',10);
194
    if (document.getElementById("pointtype").className == 'tracker') {
195
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
196
    } else if (document.getElementById("pointtype").className == 'marine') {
197
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
198
    } else {
199
	createCookie('MapTrack',document.getElementById("pointident").className,1);
200
    }
201
    window.location.reload();
202
}
203
function show3D() {
204
    createCookie('MapFormat','3d',10);
205
    if (document.getElementById("pointtype").className == 'tracker') {
206
	createCookie('MapTrackTracker',document.getElementById("pointident").className,1);
207
    } else if (document.getElementById("pointtype").className == 'marine') {
208
	createCookie('MapTrackMarine',document.getElementById("pointident").className,1);
209
    } else {
210
	createCookie('MapTrack',document.getElementById("pointident").className,1);
211
    }
212
    window.location.reload();
213
}
214
function clickPolar(cb) {
215
    createCookie('polar',cb.checked,9999);
216
    window.location.reload();
217
}
218
function clickDisplayAirports(cb) {
219
    createCookie('displayairports',cb.checked,9999);
220
    window.location.reload();
221
}
222
function clickDisplayISS(cb) {
223
    createCookie('displayiss',cb.checked,9999);
224
    updateSat();
225
}
226
function clickDisplayMinimap(cb) {
227
    createCookie('displayminimap',cb.checked,9999);
228
    window.location.reload();
229
}
230
function clickShadows(cb) {
231
    createCookie('map3dnoshadows',cb.checked,9999);
232
    window.location.reload();
233
}
234
function clickSingleModel(cb) {
235
    createCookie('singlemodel',cb.checked,9999);
236
}
237
function clickUpdateRealtime(cb) {
238
    createCookie('updaterealtime',cb.checked,9999);
239
}
240
function clickVATSIM(cb) {
241
    createCookie('filter_ShowVATSIM',cb.checked,2);
242
}
243
function clickIVAO(cb) {
244
     createCookie('filter_ShowIVAO',cb.checked,2);
245
}
246
function clickphpVMS(cb) {
247
    createCookie('filter_ShowVMS',cb.checked,2);
248
}
249
function clickSBS1(cb) {
250
    createCookie('filter_ShowSBS1',cb.checked,2);
251
}
252
function clickAPRS(cb) {
253
    createCookie('filter_ShowAPRS',cb.checked,2);
254
}
255
function clickDisplayGroundStation(cb) {
256
    createCookie('show_GroundStation',cb.checked,2);
257
    window.location.reload();
258
}
259
function clickDisplayWeatherStation(cb) {
260
    createCookie('show_WeatherStation',cb.checked,2);
261
    window.location.reload();
262
}
263
function clickDisplayWeather(cb) {
264
    createCookie('show_Weather',cb.checked,2);
265
//    window.location.reload();
266
}
267
function clickDisplayLightning(cb) {
268
    createCookie('show_Lightning',cb.checked,2);
269
    window.location.reload();
270
}
271
function clickDisplayFires(cb) {
272
    createCookie('show_Fires',cb.checked,2);
273
    window.location.reload();
274
}
275
function clickDisplay2DBuildings(cb) {
276
    createCookie('Map2DBuildings',cb.checked,2);
277
    window.location.reload();
278
}
279
280
function unitdistance(selectObj) {
281
    var idx = selectObj.selectedIndex;
282
    var unit = selectObj.options[idx].value;
283
    createCookie('unitdistance',unit,9999);
284
}
285
function unitspeed(selectObj) {
286
    var idx = selectObj.selectedIndex;
287
    var unit = selectObj.options[idx].value;
288
    createCookie('unitspeed',unit,9999);
289
}
290
function unitaltitude(selectObj) {
291
    var idx = selectObj.selectedIndex;
292
    var unit = selectObj.options[idx].value;
293
    createCookie('unitaltitude',unit,9999);
294
}
295
296
function addarchive(begindate,enddate) {
297
    console.log('Add archive');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
298
    createCookie('archive',true,2);
299
    createCookie('archive_begin',begindate,2);
300
    createCookie('archive_end',enddate,2);
301
    createCookie('archive_speed',document.getElementById("archivespeed").value,2);
302
    window.location.reload();
303
}
304
function noarchive() {
305
    console.log('Exit archive!');
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
306
    delCookie('archive');
307
    delCookie('archive_begin');
308
    delCookie('archive_end');
309
    delCookie('archive_speed');
310
    window.location.reload();
311
}
312
function msgbox(text,buttontext) {
313
	buttontext = buttontext || "OK";
314
	$("<div>" + text + "</div>").dialog({
315
	    dialogClass: "no-close",
316
	    buttons: [{
317
		text: buttontext,
318
		click: function() {
319
		    $( this ).dialog( "close" );
320
		    $(this).remove();
321
		}
322
	    }]
323
	});
324
}
325
function generateRandomPoint (latitude,longitude,height,diff,radius) {
326
327
	//console.log('height: '+height+' - diff: '+diff);
328
	radius = Math.random()*radius;
329
	latitude = latitude*(Math.PI/180.0);
330
	longitude = longitude*(Math.PI/180.0);
331
	
332
	const sinLat = 	Math.sin(latitude)
333
	const cosLat = 	Math.cos(latitude)
334
335
	/* go fixed distance in random direction*/
336
	const bearing = Math.random() * Math.PI*2
337
	const theta = radius/6371000
338
	const sinBearing = Math.sin(bearing)
339
	const cosBearing = Math.cos(bearing)
340
	const sinTheta = Math.sin(theta)
341
	const cosTheta = Math.cos(theta)
342
    
343
	latitude = Math.asin(sinLat*cosTheta+cosLat*sinTheta*cosBearing);
344
	longitude = longitude + Math.atan2( sinBearing*sinTheta*cosLat, cosTheta-sinLat*Math.sin(latitude ));
345
	/* normalize -PI -> +PI radians */
346
	longitude = ((longitude+(Math.PI*3))%(Math.PI*2))-Math.PI
347
	var h = height+(Math.random()*diff)
348
	//console.log('h: '+h);
349
	return {
350
	    latitude: latitude/(Math.PI/180.0),
351
	    longitude: longitude/(Math.PI/180.0),
352
	    height: h
353
	};
354
}
355
function getColor(colorStart,colorEnd,colorCount,step) {
356
	var alpha = (1.0/colorCount)*step;
357
	return {
358
	    r: colorStart[0]*alpha+(1-alpha)*colorEnd[0],
359
	    v: colorStart[1]*alpha+(1-alpha)*colorEnd[1],
360
	    b: colorStart[2]*alpha+(1-alpha)*colorEnd[2]
361
	};
362
}